#include "CWinTest.h"

CButton::CButton()
{
    m_lpText = nullptr;
    m_MenuOrId = nullptr;
    RtlZeroMemory(&m_rc, sizeof(RECT));
}

CButton::CButton(CRect rc, LPCTSTR lpText, HMENU MenuOrId) : 
    m_lpText(lpText),
    m_MenuOrId(MenuOrId)
{
    m_rc.left = rc.left;
    m_rc.top = rc.top;
    m_rc.right = rc.right;
    m_rc.bottom = rc.bottom;
}

CButton::~CButton()
{
}

LRESULT CButton::OnDestroyHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    PostQuitMessage(0);
    return 0;
}

LRESULT CButton::OnCreateHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    m_Button.Create(L"Button", m_hWnd, m_rc, m_lpText, WS_CHILD | WS_VISIBLE, 0, m_MenuOrId);
    return 0;
}

CWinTest::CWinTest() :
    m_Button(CRect(0, 0, 100, 20), _T("Test"), (HMENU)IDD_BUTTON_TEST)
{
}

CWinTest::~CWinTest()
{
}

LRESULT CWinTest::OnDestroyHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    PostQuitMessage(0);
    return 0;
}

LRESULT CWinTest::OnPaintHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    PAINTSTRUCT Ps = { 0 };
    PCWCH lpString = _T("HelloWOrld");
    HDC hDC = BeginPaint(&Ps);
    TextOut(hDC, 0, 0, lpString, wcslen(lpString));
    EndPaint(&Ps);
    return 0;
}

LRESULT CWinTest::OnCreateHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    RECT rc = { 100,70,200,90 };
    m_Button.Create(m_hWnd, rc, NULL, WS_CHILD | WS_VISIBLE);
    CenterWindow();
    return 0;
}

LRESULT CWinTest::OnCommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
    MessageBox(_T("Button"));
    return 0;
}

